package com.sptan.ssmp.controller;


import com.sptan.ssmp.dto.auth.AuthRequest;
import com.sptan.ssmp.dto.auth.AuthResponse;
import com.sptan.framework.core.ResultEntity;
import com.sptan.ssmp.service.AdminUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/auth")
@RequiredArgsConstructor
public class AuthenticationController {
    private final AdminUserService adminUserService;

    @PostMapping("/signup")
    public ResponseEntity<ResultEntity<AuthResponse>> register(@RequestBody AuthRequest request) {
        return ResponseEntity.ok(adminUserService.register(request.getUsername(), request.getPassword()));
    }

    @PostMapping("/login")
    public ResponseEntity<ResultEntity<AuthResponse>> login(@RequestBody AuthRequest request) {
        return ResponseEntity.ok(adminUserService.login(request));
    }
}
